
import { mainPageList } from "@/app.config"
import { toUserLogin } from "./routers"
import { userStore } from "@/store";
/**路由拦截器 */
export default [
  /**登录拦截 */
  function (ctx, next, error) {
    const needLoginItem = mainPageList.find(val => ctx.router.indexOf(val.url) >= 0)
    if (needLoginItem && needLoginItem.needLogin && !userStore.userInfo.id) {
      toUserLogin().then((res) => {
        if (res != null) {
          next()
        } else {
          error()
        }
      }).catch(() => {
        error()
      })
    } else {
      next()
    }
  },
]